package com.fact.models;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.fact.dto.NavDTO;
import com.fact.utils.connection.ConnectionManager;

public class LeftNavService {
	
	
	public ArrayList<NavDTO> getLeftNavNodeList(String userId)
	{
		NavDTO n=null;
		ArrayList<NavDTO> nodeList=new ArrayList<NavDTO>();
		Connection conn = ConnectionManager.getConnection();
		String sql="Select brand.MAKE_ID,brand.MAKE_NAME,market.MARKET_ID,market.MARKET_NAME, " +
							   " r.role_id from RESPONSIBILITIES r,MST_MAKES brand , MST_MARKETS market Where user_id=? " +
							   " And r.MAKE_ID=brand.MAKE_ID and r.MARKET_ID=market.MARKET_ID " +
							   " order by brand.MAKE_ID,market.MARKET_ID";
		   
		   PreparedStatement stmt = null;
		   ResultSet r = null;
			try
			{
				stmt = conn.prepareStatement(sql);
				stmt.setString(1, userId);
				r = stmt.executeQuery();
				while (r.next())
				{
					n=new NavDTO();
					n.setMakeId(r.getInt("MAKE_ID"));
					n.setMakeName(r.getString("MAKE_NAME"));
					n.setMarketId(r.getInt("MARKET_ID"));
					n.setMarketName(r.getString("MARKET_NAME"));
					nodeList.add(n);
				}
			} 
			catch (Exception e){e.printStackTrace();}
	 		finally{try{stmt.close();ConnectionManager.closeConnection(conn);} catch (Exception e)
				{e.printStackTrace();}stmt = null;conn = null;}
		
		
		return nodeList;
	}
	

}
